/*
 * @Author: yangzonglong
 * @Date: 2021-01-21 14:20:01
 * @version: v1.0.0
 * @Descripttion: 统一状态码提示
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-02-04 14:36:27
 * @Auditor: 
 */
import React from 'react';
import { Button } from 'antd';
import { useTranslation } from 'react-i18next';
import history from './../../app/history';
import { HOME_PATH } from './../../app/automatic/package';
import cls from './result.module.scss'

const img403 = require('./img/403.svg');
const img404 = require('./img/404.svg');

export interface ResultProps {
  code: 404 | 403;
  title?: string;
}

const defaultTitle = {
  404: '抱歉，你访问的页面不存在',
  403: '抱歉，你无权访问该页面'
}

const imgMap = {
  404: img404,
  403: img403
}

const toHomePath = () => history.push(HOME_PATH);

export default ({ code, title }: ResultProps) => {

  const { t } = useTranslation();

  return (
    <div className={cls.box}>
      <img src={imgMap[code]} />
      <div>
        <h2>{code}</h2>
        <p>{title || t(defaultTitle[code])}</p>
        {HOME_PATH && (
          <Button onClick={toHomePath} type='primary'>返回首页</Button>
        )}
      </div>
    </div>
  )
}